using System.Collections.Generic;
using UnityEngine;

public class AudioController : Instance<AudioController>
{
	public List<AudioSource> loopList_Sound = new List<AudioSource>();

	public List<AudioSource> loopList_Music = new List<AudioSource>();

	public AudioSource music_main;

	public AudioSource music_ui;

	public AudioSource sound_audience_man;

	public AudioSource sound_audience_playing;

	public AudioSource sound_audience_playing_intense;

	public AudioSource sound_audience_women;

	public AudioSource sound_ball_dribble;

	public AudioSource sound_ballhitbasketry;

	public AudioSource sound_button;

	public AudioSource sound_cheer_score;

	public AudioSource sound_countdown;

	public AudioSource sound_dunk;

	public AudioSource sound_getcoin;

	public AudioSource sound_getgem;

	public AudioSource sound_layup;

	public AudioSource sound_lose;

	public AudioSource sound_net;

	public AudioSource sound_shoerubground;

	public AudioSource sound_timeup;

	public AudioSource sound_win;

	public AudioSource sound_changeModeOrTeam;

	public AudioSource sound_dialog;

	public AudioSource sound_normalcard;

	public AudioSource sound_specialcard;

	public AudioSource sound_tag;

	public AudioSource sound_unlock;

	public AudioSource sound_levelup;

	public AudioSource sound_whistle;

	public AudioSource sound_achievestar;

	public AudioSource sound_audience_whistle;

	public AudioSource sound_defense;

	public AudioSource sound_catch;

	public AudioSource sound_weak;

	public AudioSource sound_costcoin;

	public AudioSource sound_costgem;

	public AudioSource sound_s_card;

	public void play(AudioType audioType)
	{
		AudioSource audioSource = null;
		bool flag = false;
		switch (audioType)
		{
		case AudioType.Music_main:
			flag = true;
			audioSource = music_main;
			break;
		case AudioType.Music_ui:
			flag = true;
			audioSource = music_ui;
			break;
		case AudioType.Sound_audience_man:
			audioSource = sound_audience_man;
			break;
		case AudioType.Sound_audience_playing:
			audioSource = sound_audience_playing;
			break;
		case AudioType.Sound_audience_playing_intense:
			audioSource = sound_audience_playing_intense;
			break;
		case AudioType.Sound_audience_women:
			audioSource = sound_audience_women;
			break;
		case AudioType.Sound_ballhitbasketry:
			audioSource = sound_ballhitbasketry;
			break;
		case AudioType.Sound_ball_dribble:
			audioSource = sound_ball_dribble;
			break;
		case AudioType.Sound_button:
			audioSource = sound_button;
			break;
		case AudioType.Sound_cheer_score:
			audioSource = sound_cheer_score;
			break;
		case AudioType.Sound_countdown:
			audioSource = sound_countdown;
			break;
		case AudioType.Sound_dunk:
			audioSource = sound_dunk;
			break;
		case AudioType.Sound_getcoin:
			audioSource = sound_getcoin;
			break;
		case AudioType.Sound_getgem:
			audioSource = sound_getgem;
			break;
		case AudioType.Sound_layup:
			audioSource = sound_layup;
			break;
		case AudioType.Sound_lose:
			audioSource = sound_lose;
			break;
		case AudioType.Sound_net:
			audioSource = sound_net;
			break;
		case AudioType.Sound_shoerubground:
			audioSource = sound_shoerubground;
			break;
		case AudioType.Sound_timeup:
			audioSource = sound_timeup;
			break;
		case AudioType.Sound_win:
			audioSource = sound_win;
			break;
		case AudioType.Sound_changeModeOrTeam:
			audioSource = sound_changeModeOrTeam;
			break;
		case AudioType.Sound_dialog:
			audioSource = sound_dialog;
			break;
		case AudioType.Sound_normalcard:
			audioSource = sound_normalcard;
			break;
		case AudioType.Sound_specialcard:
			audioSource = sound_specialcard;
			break;
		case AudioType.Sound_tag:
			audioSource = sound_tag;
			break;
		case AudioType.Sound_unlock:
			audioSource = sound_unlock;
			break;
		case AudioType.Sound_levelup:
			audioSource = sound_levelup;
			break;
		case AudioType.Sound_whistle:
			audioSource = sound_whistle;
			break;
		case AudioType.Sound_achievestar:
			audioSource = sound_achievestar;
			break;
		case AudioType.Sound_audience_whistle:
			audioSource = sound_audience_whistle;
			break;
		case AudioType.Sound_defense:
			audioSource = sound_defense;
			break;
		case AudioType.Sound_catch:
			audioSource = sound_catch;
			break;
		case AudioType.Sound_weak:
			audioSource = sound_weak;
			break;
		case AudioType.Sound_costcoin:
			audioSource = sound_costcoin;
			break;
		case AudioType.Sound_costgem:
			audioSource = sound_costgem;
			break;
		case AudioType.Sound_s_card:
			audioSource = sound_s_card;
			break;
		}
		if (!(audioSource != null))
		{
			return;
		}
		if (audioSource.loop)
		{
			addToLooplist(audioSource, flag);
		}
		if (flag)
		{
			if (GameData.isMusicOn)
			{
				audioSource.Play();
			}
		}
		else if ((UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex != 4 || !MyScreen.isSuperLowPhone) && GameData.isSoundOn)
		{
			audioSource.Play();
		}
	}

	public void stop(AudioType soundType)
	{
		AudioSource audioSource = null;
		bool isMusic = false;
		switch (soundType)
		{
		case AudioType.Music_ui:
			audioSource = music_ui;
			break;
		case AudioType.Sound_audience_playing:
			audioSource = sound_audience_playing;
			break;
		}
		if (audioSource != null)
		{
			audioSource.Stop();
			removeFromLoopList(audioSource, isMusic);
		}
	}

	public void turnOffMusic()
	{
		for (int i = 0; i < loopList_Music.Count; i++)
		{
			loopList_Music[i].Stop();
		}
	}

	public void turnOnMusic()
	{
		for (int i = 0; i < loopList_Music.Count; i++)
		{
			loopList_Music[i].Play();
		}
	}

	public void turnOffSound()
	{
		for (int i = 0; i < loopList_Sound.Count; i++)
		{
			loopList_Sound[i].Stop();
		}
	}

	public void turnOnSound()
	{
		for (int i = 0; i < loopList_Sound.Count; i++)
		{
			loopList_Sound[i].Play();
		}
	}

	public void pause()
	{
		turnOffMusic();
		turnOffSound();
	}

	public void resume()
	{
		turnOnSound();
		turnOnMusic();
	}

	private void addToLooplist(AudioSource audio, bool isMusic)
	{
		if (isMusic)
		{
			if (!loopList_Music.Contains(audio))
			{
				loopList_Music.Add(audio);
			}
		}
		else if (!loopList_Sound.Contains(audio))
		{
			loopList_Sound.Add(audio);
		}
	}

	private void removeFromLoopList(AudioSource audio, bool isMusic)
	{
		if (isMusic)
		{
			loopList_Music.Remove(audio);
		}
		else
		{
			loopList_Sound.Remove(audio);
		}
	}
}
